function P=newplayer(varargin)
% newplayer: create a player object for simulation with MADS 
%
% SYNTAX:
%   P = newplayer(prop1,value1,...)
%   Return generated MADS.Player object P with specified properties
%   Type "newplayer('pos',[0,0])" to see available properties and their default values. 
%   
% EXAMPLE:
%
%   P1=newplayer('pos',randn(1,2),'motion','random','speed',10,'legend','r')
%   P2=newplayer('pos',randn(1,2),'motion','random','speed',2,'legend','b')
%   G=newgame({P1,P2},'max_step',100,'pause','pause;')
%   G=simgame(G)
%
%  The above example simulates a game with two players with random motion.
%  In this game, players have random initial position, different speeds and colors. 
%  More interesting examples can be seen by running DEMO_MADS.M or EX_*.M.
%   
% See also NEWGAME, SIMGAME

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com



P=struct('type','MADS.Player',varargin{:});
P=set_field(P,'pos',[0,0]);
if length(P.pos)==3,
    P=set_field(P,'ang',[0,0,0]);
else,
    P=set_field(P,'ang',[0]);
end;
P=set_field(P,'speed',1);
P=set_field(P,'ang_speed',1);
P=set_field(P,'motion','');
P=set_field(P,'strategy','');
P=set_field(P,'action',[]);
P=set_field(P,'debug','');
P=set_field(P,'legend','');
P=set_field(P,'info','');
if class(P.info)=='char',
    P.info=newinfo(P.info);
end;

P=set_field(P,'plot_components',[]);
P=set_field(P,'plot_labels',{});
P=set_field(P,'icon','circle');
P=set_field(P,'ico',[]);
if ~isempty(P.icon),
    P.ico=newicon(P.icon);
end;

P=set_field(P,'image','');
P=set_field(P,'img',[]);
if ~isempty(P.image),
    P.img=newimage(P.image);
end;

P=set_field(P,'is_gameover',0);
P=set_field(P,'delta_ang_func','def_delta_ang_func');
P=set_field(P,'delta_pos_func','def_delta_pos_func');
P=set_field(P,'t_func','def_t_func');
P=set_field(P,'step_func','def_step_player');
P=set_field(P,'ode_func','def_ode_func');
P=set_field(P,'calc_Vars_func','def_calc_Vars');
P=set_field(P,'calc_pos_ang_func','def_calc_pos_ang');
P=set_field(P,'draw_player_func','def_draw_player');
P=set_field(P,'draw_player_trace_func','def_draw_player_trace');
P=set_field(P,'Vars',[P.pos,P.ang]);
P.trace=P.pos;

P=set_player_motion(P);
